* 〜〜〜〜〜〜〜〜〜〜〜〜 * 〜〜〜 ハノイの塔 〜〜〜 * 〜〜〜〜〜〜〜〜〜〜〜〜 * * アセンブラでハノイの塔を解くためのプログラムです。 * .R 実行形式にして TYPE すると、解法が“図解”されます。 * 円盤の枚数は次の N で指定します。 N:=7 * 以下は、変更する必要はありません。 ESC:=27 put .macro c .dc.b c .endm xline .macro n,c .dcb.b n,c .endm clear .macro .dc.b ESC,'*' .endm locate .macro x,y .dc.b ESC,'=',' '+y,' '+x .endm windowx:=96 windowy:=31 disk:='%' space:=' ' pole:='|' base:='#' core:=2 hat:=2 width:=N+core center2:=windowx/2 center1:=center2-width*2 center3:=center2+width*2 left:=center1-width right:=center3+width top:=(windowy-N)/2-hat bottom:=top+hat+N clear locate left,bottom xline right-left+1,base i:=1 .rept 3 j:=top .rept bottom-top locate center%i,j put pole j:=j+1 .endm i:=i+1 .endm number1:=N number2:=0 number3:=0 i:=1 .rept N size1%i:=width-i locate center1-size1%i,bottom-i xline size1%i*2+1,disk i:=i+1 .endm move_disk .macro a,b p:=a q:=b i:=number%p j:=bottom-i .rept N-i+hat+1 locate center%p-size%p%i,j-1 xline size%p%i*2+1,disk locate center%p-size%p%i,j xline size%p%i,space put pole xline size%p%i,space j:=j-1 .endm j:=center%p-size%p%i locate j,top-2 xline size%p%i*2+1,disk locate j,top-1 xline size%p%i*2+1,space .if center%p